home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / amos / amoslist-0295.lzh / AMOSLIST / text0175.txt < prev    next >
Encoding:
Text File  |  1995-03-01  |  3.5 KB  |  103 lines

  1. On Fri, 17 Feb 1995, Max Monahan wrote:
  2.  
  3. [...]
  4. >   Now I want the cars to have some interaction with the background. I would 
  5. > like to have a track, or perhaps just some obstacles to avoid which would
  6. > cause damage also. What is the best way of going about achieving collision
  7. > detection with the background and with various objects around the track.
  8. > e.g. a grandstand or fence or an oil slick.
  9. >    The cars are currently bobs but there is probably no reason why they 
  10. > cannot be sprites. 
  11. >    Should I just draw the background in a certain colour range and check
  12. > for collision with certain colours
  13.  
  14.    I don't think this is the "best" way...
  15.  
  16. > ( I think this method was used in the
  17. > space ship shoot em up game which came with AMOS,-its name escapes me)
  18. > or create the background using bobs and use bob collision techniques.
  19. >    Any suggestions?
  20.  
  21.   WHat I would suggest is a Background collision lookup table... this also
  22.   works especially well if you plan to render the course from a set of
  23.   tile primitives.. 
  24.  
  25.   Basically you just look up the 'collision' status for whatever 'tile' the
  26.   car is on... So you have to compute which tile your on by examing the
  27.   game map... Example:
  28.  
  29.   Tiles:        Description         Collison Status            
  30.          1 -> a piece of track           0  (ie. no collision status)
  31.          2 -> grass                      0
  32.          3 -> tree                       1  (ie. collision)
  33.  
  34.      Tiles are 16x16 pixels for example.
  35.  
  36.   Race Track Map:
  37.  
  38.       2222222222  --> This would give you a (160,96) race track 
  39.    |  2222332222      (ie. grass on the side of the track with 3 trees)
  40.    +  1111111111
  41.    y  1111111111  Of course in your game you will need more tiles and
  42.    |  2222222232  a bigger map but the idea is exactly the same.
  43.    V  2222222222
  44.        ---+x-->  
  45.     
  46.     You can compute at what (xm,ym) in the map (ie. map co-ordinates) your
  47.     car is at from its pixel co-ordinates (xp,yp) using:
  48.  
  49.         xm = xp / (tile width) = xp / 16
  50.                 ym = yp / (tile height)= yp / 16
  51.     
  52.     Tile Under Car = Map(xm,ym)
  53.  
  54.     Now that you know what tile your on you just use it to look up the
  55.     collision status...
  56.  
  57.     if Collsion(Map(xm,ym))=1
  58.        ** collison **
  59.     else
  60.        ** no collisn **
  61.  
  62.     For speed you should make the 'divisions' in the pixel->map co-ordinate
  63.     formulas either shifts or just pre-calculated.  Depdending on how
  64.     you decide to implement the Game Map (ie. array/memory bank/etc..)
  65.     you can do the same things.
  66.  
  67.     One other thing that could make it fast is caching current tile lookups
  68.     but I have never bothered to do this... 
  69.  
  70.     In your case you would probably want to set up most of the screen as
  71.     the race track so you would need a (320/16)x(192/16) or 20x19 tile
  72.     map.
  73.   
  74.     I hope this helps... if you need any clarifications just ask.. me 
  75.     english not good.
  76.  
  77. > Also there is a small amount of flicker which I would like to get rid of.
  78. > Any suggestions on removing that. i.e. Should I be using autoback 0 with 
  79. > the bob update off and bob clear,bob draw techniques?  I had a go at it
  80. > but couldn't get it working. Any suggestions on that one also would be
  81. > appreciated.
  82.  
  83.   I use this technique... but I can't check any code right now.. but
  84.   basically you turn off automatic bob update then you must expiclity
  85.   say when to update your bob's... 
  86.  
  87.     .
  88.         .
  89.         .
  90.         Bob Update
  91.         Screen Swap
  92.         Wait Vbl
  93.         .  
  94.   
  95.                                mike   
  96. > -thanks in advance
  97. > Max 
  98.  
  99.